Here are the steps that you need to get started with using OPC-UA modelling approach in your code:
- Create an instance of UAModelClient class that will use the information model resident in the OPC server. You obtain this UAModelClient object by calling a static method UAModelClient.CreateWithServerModel().
- When you want to work with a node in the OPC server, obtain the corresponding node object by calling the GetNode method on the UAModelClient object. There are also extension methods that are useful to obtain nodes with a type that you expect. For example, to obtain a node for an analog variable of type TValue, use the UAModelClientExtension<TValue> extension method.
-
- If you want to read data from the node, call the ReadNode method on the UAModelClient object, passing it the node object, and optionally the so-called modelling tag. Use UAModellingTags.VariableValue to operate only on the value of the variable. Use UAModellingTags.VariableProperty to operate on all variable properties. After the ReadNode call, the properties on the node object contain the values obtained. For example, the Value property contains the current value of the variable. Or, the EURange property contains the engineering units range.
- If you want to write data into the node, set the properties of the node objects (such as the Value property), and then call the WriteNode method on the UAModelClient object. You can optionally use the modelling tags, as with the ReadNode method.
- If you want to subscribe to (or unsubscribe from) changes in the node data, call the SubscribeNode method on the UAModelClient object, passing it the “active” flag (determines whether you want to subscribe or unsubscribe) and the node object. You can optionally use the modelling tags, as with the ReadNode method. The properties of the node object (such as the Value property) will be automatically be updated with changes from the OPC server.